#!/usr/bin/env python

# INSTRUCTIONS:
# 
# (1) Implement the TextMessage class accordig to docstring specifications.


class CellPhone(object):
    '''Simple cell phone that can make & receive calls.

    Instance attributes:

    owner -- string name of the cell phone owner
    '''
    def __init__(self, owner):
        self.owner = owner
        self.ringtone = "ring ring..."
        self.contacts = {}

    def makeCall(self, other_phone):
        '''This function will print "calling ... <recipient name>"
        '''
        print self.owner, "-- calling", other_phone.owner
        other_phone.receiveCall(self)
        return

    def receiveCall(self, other_phone):
        '''This function will print "receiving call from ... <recipient name>"
        and then calls the function to ring.
        '''
        print self.owner, "-- receiving call from", other_phone.owner
        self.ringTone(other_phone)

    def ringTone(self, phone):
        "Print out the sound of the ring tone on this phone"
        for person in self.contacts:
            if person == phone.owner:
                print self.contacts[person]
                return

        print self.ringtone
        return

    def addContact(self, person, ringtone):
        if self.contacts.get(person.owner) == None: 
            self.contacts[person.owner] = ringtone
            print person.owner, "added to contacts."
            return
        else:
            print person.owner, "already in contacts."

if __name__ == '__main__':
    phone1 = CellPhone('Person1')
    phone2 = CellPhone('Person2')
    
    phone1.makeCall(phone2)
    
    phone2.addContact(phone1, "Beep Beep") 
    phone1.makeCall(phone2)
    
    phone1.ringtone = "Dum buh dum bee doh"
    phone2.makeCall(phone1)
